<?php
$arrWeb = array();
$arrWeb[0] = "fon.uswin.us";	//永豐
$arrWeb[1] = "union77.us";	 //萬寶

set_time_limit(0);
$strWeb = $_SERVER[argv][1];

$strLogError = "\n".$strWeb."  Time: ".date("Y-m-d H:i:s")."\n";
$_isDBExist = "no";
$_DBSite = "Master";
$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/".$strWeb."/secure";
include($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
if($_strLogErr != ""){
	exit($strLogError.$_strLogErr);
}

$strSQL = "SHOW MASTER STATUS";
if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
	exit($strLogError."Error:".PMA_mysql_error($_ConnMaster)."\n");
}

$Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC);
$intMasterPos =	$Rows["Position"];

$_DBSite = "Query";
$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/".$strWeb."/secure";
include($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
if($_strLogErr != ""){
	exit($strLogError.$_strLogErr);
}

$strSQL = "SHOW SLAVE STATUS";
if(!$RS = PMA_mysql_query($strSQL, $_ConnQuery)){
	exit($strLogError."Error:".PMA_mysql_error($_ConnQuery)."\n");
}

$Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC);
$intSlavePos =	$Rows["Exec_master_log_pos"];

if($intMasterPos - $intSlavePos > 10000){
	$strSQL = "insert into `bet_BetControl`(`BetKey`) values('DBNotSync')";
	$strLogError .= "is Async (".$intMasterPos.", ".$intSlavePos.")!";
}else{
	$strSQL = "delete from `bet_BetControl` where `BetKey` = 'DBNotSync'";
	$strLogError .= "is Sync (".$intMasterPos.", ".$intSlavePos.")!";
}

if(!$RS = PMA_mysql_query($strSQL, $_ConnQuery)){
	if(mysql_errno($_ConnQuery) != 1062)exit($strLogError."Error:".PMA_mysql_error($_ConnQuery)."\n");
}
exit($strLogError." End (".date("Y-m-d H:i:s").")\n");
?>